//
//  ViewController.m
//  ybUIView
//
//  Created by mac on 15-11-30.
//  Copyright (c) 2015年 1. All rights reserved.
//

#import "ViewController.h"
#import "BarViewController.h"

@interface ViewController ()<UITableViewDelegate,inDelegate>
{
    NSMutableArray *name;
    NSMutableArray *tel;
    NSIndexPath *index;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.title = @"电话簿";
    name = @[@"张三",@"李四",@"王五"].mutableCopy;
    tel = @[@"13612345678",
            @"13311145678",
            @"14713612345"
            ].mutableCopy;
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return name.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.textLabel.text = name[indexPath.row];
    cell.detailTextLabel.text = tel[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    BarViewController *bar = [[BarViewController alloc]initWithStyle:UITableViewStyleGrouped];
    bar.name = name[indexPath.row];
    bar.tel = tel[indexPath.row];
    [self.navigationController pushViewController:bar animated:YES];
}

- (void)inname:(NSString *)text
{
    NSMutableArray *arr = tel;
    [arr replaceObjectAtIndex:index.row withObject:text];
    NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
